package com.jvyou.framework.controller;



import com.jvyou.framework.domain.dto.SysSettingGroupDto;
import com.jvyou.framework.domain.entity.SysSettingGroup;
import com.jvyou.framework.service.SysSettingGroupService;
import org.springframework.web.bind.annotation.*;
import lombok.RequiredArgsConstructor;
import cn.dev33.satoken.annotation.SaCheckPermission;
import java.util.List;
import com.jvyou.common.annotation.Log;
import com.jvyou.common.core.domain.model.PageResult;
import com.jvyou.common.core.domain.model.Result;
import com.jvyou.common.enums.log.BusinessType;
import com.jvyou.common.enums.result.HttpCodeEnum;


/**
 * 系统设置分组(SysSettingGroup)表控制层
 *
 * @author 橘柚
 * @since 2025-05-30 11:01:44
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/sysSettingGroup")
public class SysSettingGroupController  {
    
    private final SysSettingGroupService sysSettingGroupService;
    
     /**
     * 查询系统设置分组列表
     *
     * @param dto 查询参数
     * @return 系统设置分组
     */
    @GetMapping("/list")
    @SaCheckPermission("sys:sysSettingGroup:list")
    @Log(title = "查询系统设置分组列表", businessType = BusinessType.OTHER)
    public Result<List<SysSettingGroup>> list(@ModelAttribute SysSettingGroupDto dto) {
        return Result.success(sysSettingGroupService.listSysSettingGroup(dto));
    }

     /**
     * 分页查询系统设置分组列表
     *
     * @param dto 查询参数
     * @return 系统设置分组
     */
    @GetMapping("/page")
    @SaCheckPermission("sys:sysSettingGroup:page")
    @Log(title = "分页查询系统设置分组列表", businessType = BusinessType.OTHER)
    public Result<PageResult<SysSettingGroup>> page(@ModelAttribute SysSettingGroupDto dto) {
        return Result.success(sysSettingGroupService.pageSysSettingGroup(dto));
    }

    /**
     * 通过主键查询系统设置分组单条
     *
     * @param id 系统设置分组主键
     * @return 系统设置分组
     */
    @GetMapping("/{id}")
    @Log(title = "通过主键查询系统设置分组")
    @SaCheckPermission("sys:sysSettingGroup:get")
    public Result<SysSettingGroup> selectOne(@PathVariable("id") Long id) {
        return Result.success(sysSettingGroupService.getById(id));
    }

    /**
     * 新增系统设置分组
     *
     * @param sysSettingGroup 系统设置分组实体对象
     * @return 新增系统设置分组结果
     */
    @PostMapping
    @Log(title = "新增系统设置分组",  businessType = BusinessType.INSERT)
    @SaCheckPermission("sys:sysSettingGroup:insert")
    public Result<SysSettingGroup> insert(@RequestBody SysSettingGroup sysSettingGroup) {
        boolean success = sysSettingGroupService.save(sysSettingGroup);
        return success ? Result.success(sysSettingGroup) : Result.error(HttpCodeEnum.ADD_FAIL);
    }
    
     /**
     * 修改系统设置分组
     *
     * @param sysSettingGroup 系统设置分组实体对象
     * @return 修改系统设置分组结果
     */
    @PutMapping("/updateById")
    @SaCheckPermission("sys:sysSettingGroup:update")
    @Log(title = "修改系统设置分组数据", businessType = BusinessType.UPDATE)
    public Result<SysSettingGroup> updateById(@RequestBody SysSettingGroup sysSettingGroup) {
        boolean success = sysSettingGroupService.updateById(sysSettingGroup);
        return success ? Result.success(sysSettingGroup) : Result.error(HttpCodeEnum.UPDATE_FAIL);
    }
    

    /**
     * 删除系统设置分组数据
     *
     * @param id 系统设置分组主键
     * @return 删除系统设置分组结果
     */
    @DeleteMapping("/{id}")
    @SaCheckPermission("sys:sysSettingGroup:delete")
    @Log(title = "删除系统设置分组",  businessType = BusinessType.DELETE)
    public Result<Boolean> delete(@PathVariable("id") Long id) {
        boolean success = sysSettingGroupService.removeById(id);
        return success ? Result.success(true) : Result.error(HttpCodeEnum.DELETE_FAIL);
    }
}

